package com.test03_类与对象;

/**
 * this关键字
 */
public class YootkDemo_05 {

    public static void main(String[] args) {
        Channel channel = new Channel("沐言优拓在线教育", "开启”李兴华编程训练营“");
    }
}

/**
 * 消息类
 */
class Message {
    private String title;       // 要发送的标题
    private String content;     // 要发送的内容
    private Channel channel;    // 消息通道

    public Message(Channel channel, String title, String content) {
        this.title = title;
        this.content = content;
        this.channel = channel;
    }

    // 消息发送
    public void send() {
        if (this.channel.connect()) {
            System.out.println("【Message】消息发送，消息标题：" + this.title + "、消息内容：" + this.content);
            this.channel.close();
        } else {
            System.out.println("【Message】没有可用的消息发送通道，消息发送失败...");
        }
    }
}

/**
 * 消息通道
 */
class Channel {
    private Message message;    // 消息

    public Channel(String title, String content) {
        this.message = new Message(this, title, content);
        this.message.send();
    }

    // 通道的连接
    public boolean connect() {
        System.out.println("【Channel】建立消息的发送通道...");
        return true;
    }

    // 关闭通道
    public void close() {
        System.out.println("【Channel】关闭消息通道...");
    }
}
